<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="4">
        <div class="grid-content bg-purple-dark">
          <el-input v-model="search" circle placeholder="请输入内容"></el-input>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="grid-content bg-purple-dark">
          <el-date-picker
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            v-model="date"
            type="date"
            placeholder="选择入院时间"
          >
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple-dark">
          <el-input
            v-model="phone"
            circle
            placeholder="请输入手机号"
          ></el-input>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple-dark">
          <el-input
            v-model="zhuyuanhao"
            circle
            placeholder="请输入住院号"
          ></el-input>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="grid-content bg-purple-dark">
          <el-input
            v-model="bingchuanghao"
            circle
            placeholder="请输入病床号"
          ></el-input>
        </div>
      </el-col>
      <el-col :span="2">
        <div class="grid-content bg-purple-dark">
          <el-button
            type="primary"
            @click="submit"
            icon="el-icon-search"
            circle
          ></el-button>
        </div>
      </el-col>
    </el-row>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection"> </el-table-column>
      <el-table-column label="住院号">
        <template slot-scope="scope">{{ scope.row.num }}</template>
      </el-table-column>
      <el-table-column label="姓名">
        <template slot-scope="scope">{{ scope.row.name }}</template>
      </el-table-column>
      <el-table-column label="性别">
        <template slot-scope="scope">{{ scope.row.sex }}</template>
      </el-table-column>
      <el-table-column label="年龄">
        <template slot-scope="scope">{{ scope.row.age }}</template>
      </el-table-column>
      <el-table-column label="病床号">
        <template slot-scope="scope">{{ scope.row.chuanghao }}</template>
      </el-table-column>
      <el-table-column label="主治医生">
        <template slot-scope="scope">{{ scope.row.doctors }}</template>
      </el-table-column>
      <el-table-column label="护士">
        <template slot-scope="scope">{{ scope.row.nusers }}</template>
      </el-table-column>
      <el-table-column label="住院状态">
        <template slot-scope="scope">{{ scope.row.status }}</template>
      </el-table-column>
      <el-table-column label="入院时间">
        <template slot-scope="scope" v-if="scope.row.blo">
          {{ scope.row.date }}
        </template>
      </el-table-column>
      <el-table-column label="诊断情况">
        <template slot-scope="scope">
          {{ scope.row.zdtype }}
        </template>
      </el-table-column>
      <el-table-column label="出院时间">
        <template slot-scope="scope" v-if="scope.row.blo">
          {{ scope.row.date }}
        </template>
      </el-table-column>
      <el-table-column label="操作" class="cellwidth">
        <template slot-scope="scope">
          <i class="el-icon-edit" @click="dit(scope.row.chuanghao)"></i>
          <i
            class="el-icon-circle-close"
            @click="dlele(scope.row.chuanghao)"
          ></i>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 20px">
      <el-button type="danger" @click="delmany">批量删除</el-button>
      <el-button @click="toggleSelection()">取消选择</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "Binglilist",
  data() {
    return {
      phone:"",
      search: "",
      zhuyuanhao:"",
      bingchuanghao:"",
      date: "",
      tableData: [
        // {
        //   date: "2016-05-03",
        //   name: "王小虎1",
        //   address: "上海市普陀区金沙江路 1518 弄",
        // }
        {
          num: "01",
          name: "小明",
          sex: "男",
          age: 50,
          className: "外科",
          province: "河南",
          chuanghao: 3028,
          doctors: "赵医师",
          nusers: "乔护士",
          status: "未住院",
          blo: false,
          city: "郑州",
          zdtype: "骨折",
          date: "2020-12-8",
        },
        {
          num: "02",
          name: "小明",
          sex: "男",
          age: 50,
          className: "外科",
          province: "河南",
          chuanghao: 3029,
          doctors: "赵医师",
          nusers: "乔护士",
          status: "已出院",
          blo: true,
          city: "郑州",
          zdtype: "骨折",
          date: "2020-12-8",
        },
        {
          num: "03",
          name: "小明",
          sex: "男",
          age: 50,
          className: "外科",
          province: "河南",
          chuanghao: 3030,
          doctors: "赵医师",
          nusers: "乔护士",
          status: "预住院",
          blo: false,
          city: "郑州",
          zdtype: "骨折",
          date: "2020-12-8",
        },
        {
          num: "04",
          name: "小明",
          sex: "男",
          age: 50,
          className: "外科",
          province: "河南",
          chuanghao: 3031,
          doctors: "赵医师",
          nusers: "乔护士",
          status: "未住院",
          blo: false,
          city: "郑州",
          zdtype: "骨折",
          date: "2020-12-8",
        },
        {
          num: "05",
          name: "小明",
          sex: "男",
          age: 50,
          className: "外科",
          province: "河南",
          chuanghao: 3032,
          doctors: "赵医师",
          nusers: "乔护士",
          status: "已住院",
          blo: true,
          city: "郑州",
          zdtype: "骨折",
          date: "2020-12-8",
        },
        {
          num: "06",
          name: "小明",
          sex: "男",
          age: 50,
          className: "外科",
          province: "河南",
          chuanghao: 3033,
          doctors: "赵医师",
          nusers: "乔护士",
          status: "已住院",
          blo: true,
          city: "郑州",
          zdtype: "骨折",
          date: "2020-12-8",
        },
      ],
      multipleSelection: [], //我把选中的每一个放入这个数组里面
    };
  },
  methods: {
    dit(i) {
      //编辑
      console.log(i);
    },
    dlele(num) {
      // var newarr=""
      for (let i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].chuanghao == num) {
          this.tableData.splice(i,1)
          return
        }
      }
    },
    submit() {
      console.log(this.search, this.date);
    },
    seendetail(rows) {
      //单机查看按钮
      console.log(rows);
      sessionStorage.setItem("row", JSON.stringify(rows));

      this.$router.push({
        path: "/index/binglliindex/bingliseenedit",
        query: { row: rows },
      });
    },
    delmany() {
      console.log(this.multipleSelection);
      for (let i = 0; i < this.tableData.length; i++) {
        for (let j = 0; j < this.multipleSelection.length; j++) {
          if (this.tableData[i] == this.multipleSelection[j]) {
            this.tableData.splice(i, 1);
          }
        }
      }
    },
       toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>

<style lang="scss"  scoped>
// .cellwidth{
//     // text-align: center !important;
//     // padding: 0 !important;
//     background: black;
// }
.el-icon-edit {
  padding-right: 20px;
  font-size: 18px;
  color: #16dcb8;
}
.el-icon-circle-close {
  font-size: 18px;
  color: #16dcb8;
}
</style>